# Locate libusb library
# This module defines
# LIBUSB_FOUND, if false, do not try to link to libusb
# LIBUSB_INCLUDE_DIRS, where to find the headers
# LIBUSB_LIBRARIES, the libraries to link against

find_path(LIBUSB_INCLUDE_DIR
    NAMES
    libusb.h
    PATH_SUFFIXES
    libusb-1.0   # PATHS目录中的libusb-1.0子目录
    PATHS
    /usr/include
    /usr/local/include
)

find_library(LIBUSB_LIBRARY
    NAMES
    usb-1.0
    PATH_SUFFIXES
    x86_64-linux-gnu # PATHS目录中的x86_64-linux-gnu子目录
    PATHS
    /usr/lib
    /usr/local/lib
    /lib
)

if(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARY)
    set(LIBUSB_FOUND TRUE)
else()
    set(LIBUSB_FOUND FALSE)
endif()

if(LIBUSB_FOUND)
    if(NOT LibUsb_FIND_QUIETLY)
        message(STATUS "Found libusb: ${LIBUSB_LIBRARY}")
    endif()
else()
    if(LibUsb_FIND_REQUIRED)
        message(FATAL_ERROR "libusb not found")
    endif()
endif()

set(LIBUSB_INCLUDE_DIRS ${LIBUSB_INCLUDE_DIR})
set(LIBUSB_LIBRARIES ${LIBUSB_LIBRARY})
